package com.springboot.demo.config;

import com.springboot.demo.utils.Constant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wubc683
 * @desc
 * @date 2021-07-22 16:58
 */
@Configuration
public class TopicRabbitConfig {

    @Bean
    public Queue webToClientQueue() {
        return new Queue(Constant.Rabbitmq.WEB_TO_CLIENT_QUEUE);
    }

    @Bean
    public Queue systemQueue() {
        return new Queue(Constant.Rabbitmq.TOPIC_SYSTEM_QUEUE);
    }

    @Bean
    public Queue userQueue() {
        return new Queue(Constant.Rabbitmq.TOPIC_USER_QUEUE);
    }

    @Bean
    TopicExchange webToClientExchange() {
        return new TopicExchange(Constant.Rabbitmq.WEB_TO_CLIENT_EXCHANGE);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange(Constant.Rabbitmq.TOPIC_EXCHANGE);
    }

    @Bean
    Binding bindingWebExchangeMessage() {
        return BindingBuilder.bind(webToClientQueue()).to(webToClientExchange()).with(Constant.Rabbitmq.WEB_TO_CLIENT_ROUTING_KEY);
    }

    @Bean
    Binding bindingSystemExchangeMessage() {
        return BindingBuilder.bind(systemQueue()).to(exchange()).with(Constant.Rabbitmq.TOPIC_SYSTEM_ROUTINGKEY);
    }

    @Bean
    Binding bindingUserExchangeMessage() {
        return BindingBuilder.bind(userQueue()).to(exchange()).with(Constant.Rabbitmq.TOPIC_USER_ROUTINGKEY);
    }

}